# -*- coding: utf-8 -*-

# Author: 一根鱼骨棒
# Date: 2020-10-12 08:27:21
# LastEditTime: 2023-03-19 10:02:09
# LastEditors: 一根鱼骨棒
# Description: 本开源代16码使用GPL 3.0协议
# Software: VScode
# Copyright 2020

import subprocess
from function import *
# 同步采集日志 本地使用请注释以下代码
# 需要修改仓库代码请单独使用git工具
##############################
# 初始化外网同步仓库cd
gitrepo = GitRepository(log_path, 'https://gitee.com/truelyluser/news_log.git')
gitrepo.pull()
gitway = Git(log_path)
os.chdir("D:\code\python")
print(os.getcwd())
#print(gitway.execute('git fetch --all'))
print(gitway.execute('git reset --hard'))
print(gitway.execute('git pull'))
lastweek = int(week)-1
if lastweek == '-1':
    lastweek = 52
    last_log_name = str(int(year)-1)+str(lastweek)+"added.txt"
else:
    last_log_name = str(year)+str(lastweek)+"added.txt"
if os.path.isfile(log_path+last_log_name):
    os.remove(log_path+last_log_name)
    print("删除上周采集日志")
print("下载数据同步完成")
############################# 

spiders = [
    'python D:\\Code\\python\\script\\newspider\\xinlang.py',
    'python D:\\Code\\python\\script\\newspider\\xinhua_spider.py',
    'python D:\\Code\\pytcdhon\\script\\newspider\\jw.py',
    'python D:\\Code\\python\\script\\newspider\\hsxm.py',
    # 'python D:\\Code\\python\\script\\newspider\\20ddzxx.py',
    'python D:\\Code\\python\\script\\newspider\\20dbgxx.py',
]
for program in spiders:
    p = call(program)
    print("{}——采集完成".format(program.split("\\")[-1]))
with open(log_path+'count.txt', 'r') as target:
    # 读取保存的文章数量
    saved = target.read()
    print("完成采集，累计保存{}篇文章".format(saved))
# 上传采集日志 本地使用请注释以下代码
##########################################
try:
    print(gitway.execute("git add ."))
    print(gitway.execute("git commit -m "+year+month+day+hours))
except:
    print("nothing to commit")
        
print(gitway.execute("git push origin master"))
##########################################